//
//  MainMenuViewController_iPhone.m
//  Pepperdine
//
//  Created by Michael Coats on 3/4/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "MainMenuViewController_iPhone.h"
#import "MapAppViewController_iPhone.h"
#import "WavenetAppViewController_iPhone.h"
#import "CafeAppViewController_iPhone.h"
#import "LibraryAppViewController_iPhone.h"
#import "DivisionAppViewController_iPhone.h"
#import "TemplateAppViewController_iPhone.h"
#import "AthleticsAppViewController_iPhone.h"
#import "ConvocationAppViewController_iPhone.h"
#import "CalendarAppViewController_iPhone.h"
#import "FacultyAppViewController_iPhone.h"
#import "StudentActivitiesAppViewController_iPhone.h"

int numberOfPages = 2;

@implementation MainMenuViewController_iPhone

@synthesize pageControl, scrollView;
@synthesize mapAppViewController, cafeAppViewController, wavenetAppViewController, libraryAppViewController, divisionAppViewController, tempAppViewController;
@synthesize athleticsAppViewController;
@synthesize convocationAppViewController;
@synthesize calendarAppViewController;
@synthesize facultyAppViewController;
@synthesize studentActivitiesAppViewController;

- (void)viewDidLoad {
	[super viewDidLoad];
	self.title = @"Main Menu";

	[self.view setBackgroundColor:
     [UIColor colorWithPatternImage:
      [UIImage imageWithContentsOfFile:
       [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
        @"background.png"]]]];
	
	scrollView.pagingEnabled = YES;
	[scrollView setContentSize:CGSizeMake((numberOfPages * 320.0f), 1.0f)];
	scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
	scrollView.delegate = self;
	
	pageControl.numberOfPages = numberOfPages;
	pageControl.currentPage = 0;
	[pageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];
	
	
//	UIButton *mapAppButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//	mapAppButton.frame = CGRectMake(20, 20, 80, 80);
//	[scrollView addSubview:mapAppButton];
//	[mapAppButton addTarget:self action:@selector(OpenMapApp:) forControlEvents:UIControlEventTouchUpInside];
	
	
		
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////																																						//////
	//////  We need to go through this code carefully and make sure all of our objects are created and destroyed properly.  I see that a ton of buttons and     //////
	//////  labels are created, but where are they ever deallocated?  This could be a huge memory leak if they are never autoreleased or deallocated manually.  //////
	//////  Also, is UILabel.new the same thing as [[UILabel alloc] init]?  We need to look into this.															//////
	//////																																						//////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	
	UIButton *mapAppButton = [[UIButton alloc] init];
	NSString *mapAppPath = [[NSBundle mainBundle] pathForResource:@"map_icon" ofType:@"png"];
	UIImage *mapAppImage = [UIImage imageWithContentsOfFile:mapAppPath];
	mapAppButton.frame = CGRectMake(20, 20, 80, 80);
	[mapAppButton setImage:mapAppImage forState:UIControlStateNormal];
	[scrollView addSubview:mapAppButton];
	[mapAppButton addTarget:self action:@selector(OpenMapApp:) forControlEvents:UIControlEventTouchUpInside];
	[mapAppImage release];
	[mapAppPath release];

	UILabel *mapAppLabel = UILabel.new;
	mapAppLabel.frame = CGRectMake(20, 105, 80, 20);
	[scrollView addSubview:mapAppLabel];
	mapAppLabel.text = @"Map";
	mapAppLabel.textAlignment = UITextAlignmentCenter;
	mapAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *wavenetAppButton = [[UIButton alloc] init];
	NSString *wavenetAppPath = [[NSBundle mainBundle] pathForResource:@"Wavenet_icon" ofType:@"png"];
	UIImage *wavenetAppImage = [UIImage imageWithContentsOfFile:wavenetAppPath];
	wavenetAppButton.frame = CGRectMake(120, 20, 80, 80);
	[wavenetAppButton setImage:wavenetAppImage forState:UIControlStateNormal];
	[scrollView addSubview:wavenetAppButton];
	[wavenetAppButton addTarget:self action:@selector(OpenWavenetApp:) forControlEvents:UIControlEventTouchUpInside];
	[wavenetAppImage release];
	[wavenetAppPath release];
	
	UILabel *wavenetAppLabel = UILabel.new;
	wavenetAppLabel.frame = CGRectMake(120, 105, 80, 20);
	[scrollView addSubview:wavenetAppLabel];
	wavenetAppLabel.text = @"Wavenet";
	wavenetAppLabel.textAlignment = UITextAlignmentCenter;
	wavenetAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *cafeAppButton = [[UIButton alloc] init];
	NSString *cafeAppPath = [[NSBundle mainBundle] pathForResource:@"CafeAppIcon" ofType:@"png"];
	UIImage *cafeAppImage = [UIImage imageWithContentsOfFile:cafeAppPath];
	cafeAppButton.frame = CGRectMake(220, 20, 80, 80);
	[cafeAppButton setImage:cafeAppImage forState:UIControlStateNormal];
	[scrollView addSubview:cafeAppButton];
	[cafeAppButton addTarget:self action:@selector(OpenCafeApp:) forControlEvents:UIControlEventTouchUpInside];
	[cafeAppImage release];
	[cafeAppPath release];
	
	UILabel *cafeAppLabel = UILabel.new;
	cafeAppLabel.frame = CGRectMake(220, 105, 80, 20);
	[scrollView addSubview:cafeAppLabel];
	cafeAppLabel.text = @"Cafe";
	cafeAppLabel.textAlignment = UITextAlignmentCenter;
	cafeAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *libraryAppButton = [[UIButton alloc] init];
	NSString *libraryAppPath = [[NSBundle mainBundle] pathForResource:@"Library-icon" ofType:@"png"];
	UIImage *libraryAppImage = [UIImage imageWithContentsOfFile:libraryAppPath];
	libraryAppButton.frame = CGRectMake(20, 130, 80, 80);
	[libraryAppButton setImage:libraryAppImage forState:UIControlStateNormal];
	[scrollView addSubview:libraryAppButton];
	[libraryAppButton addTarget:self action:@selector(OpenLibraryApp:) forControlEvents:UIControlEventTouchUpInside];
	[libraryAppImage release];
	[libraryAppPath release];

	
	UILabel *libraryAppLabel = UILabel.new;
	libraryAppLabel.frame = CGRectMake(20, 215, 80, 20);
	[scrollView addSubview:libraryAppLabel];
	libraryAppLabel.text = @"Library";
	libraryAppLabel.textAlignment = UITextAlignmentCenter;
	libraryAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *divisionAppButton = [[UIButton alloc] init];
	NSString *divisionAppPath = [[NSBundle mainBundle] pathForResource:@"Divisions_icon" ofType:@"png"];
	UIImage *divisionAppImage = [UIImage imageWithContentsOfFile:divisionAppPath];
	divisionAppButton.frame = CGRectMake(120, 130, 80, 80);
	[divisionAppButton setImage:divisionAppImage forState:UIControlStateNormal];
	[scrollView addSubview:divisionAppButton];
	[divisionAppButton addTarget:self action:@selector(OpenDivisionApp:) forControlEvents:UIControlEventTouchUpInside];
	[divisionAppImage release];
	[divisionAppPath release];
	
	UILabel *divisionAppLabel = UILabel.new;
	divisionAppLabel.frame = CGRectMake(120, 215, 80, 20);
	[scrollView addSubview:divisionAppLabel];
	divisionAppLabel.text = @"Divisions";
	divisionAppLabel.textAlignment = UITextAlignmentCenter;
	divisionAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *athleticsAppButton = [[UIButton alloc] init];
	NSString *athleticsAppPath = [[NSBundle mainBundle] pathForResource:@"Athletics_icon" ofType:@"png"];
	UIImage *athleticsAppImage = [UIImage imageWithContentsOfFile:athleticsAppPath];
	athleticsAppButton.frame = CGRectMake(220, 130, 80, 80);
	[athleticsAppButton setImage:athleticsAppImage forState:UIControlStateNormal];
	[scrollView addSubview:athleticsAppButton];
	[athleticsAppButton addTarget:self action:@selector(OpenAthleticsApp:) forControlEvents:UIControlEventTouchUpInside];
	[athleticsAppImage release];
	[athleticsAppPath release];
	
	UILabel *athleticsAppLabel = UILabel.new;
	athleticsAppLabel.frame = CGRectMake(220, 215, 80, 20);
	[scrollView addSubview:athleticsAppLabel];
	athleticsAppLabel.text = @"Athletics";
	athleticsAppLabel.textAlignment = UITextAlignmentCenter;
	athleticsAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *convocationAppButton = [[UIButton alloc] init];
	NSString *convocationAppPath = [[NSBundle mainBundle] pathForResource:@"Convo_icon" ofType:@"png"];
	UIImage *convocationAppImage = [UIImage imageWithContentsOfFile:convocationAppPath];
	convocationAppButton.frame = CGRectMake(20, 240, 80, 80);
	[convocationAppButton setImage:convocationAppImage forState:UIControlStateNormal];
	[scrollView addSubview:convocationAppButton];
	[convocationAppButton addTarget:self action:@selector(OpenConvocationApp:) forControlEvents:UIControlEventTouchUpInside];
	[convocationAppImage release];
	[convocationAppPath release];
	
	UILabel *convocationAppLabel = UILabel.new;
	convocationAppLabel.frame = CGRectMake(20, 325, 80, 20);
	[scrollView addSubview:convocationAppLabel];
	convocationAppLabel.text = @"Convo";
	convocationAppLabel.textAlignment = UITextAlignmentCenter;
	convocationAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *calendarAppButton = [[UIButton alloc] init];
	NSString *calendarAppPath = [[NSBundle mainBundle] pathForResource:@"Calendar_icon" ofType:@"png"];
	UIImage *calendarAppImage = [UIImage imageWithContentsOfFile:calendarAppPath];
	calendarAppButton.frame = CGRectMake(120, 240, 80, 80);
	[calendarAppButton setImage:calendarAppImage forState:UIControlStateNormal];
	[scrollView addSubview:calendarAppButton];
	[calendarAppButton addTarget:self action:@selector(OpenCalendarApp:) forControlEvents:UIControlEventTouchUpInside];
	[calendarAppImage release];
	[calendarAppPath release];
	
	UILabel *calendarAppLabel = UILabel.new;
	calendarAppLabel.frame = CGRectMake(120, 325, 80, 20);
	[scrollView addSubview:calendarAppLabel];
	calendarAppLabel.text = @"Calendar";
	calendarAppLabel.textAlignment = UITextAlignmentCenter;
	calendarAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *facultyAppButton = [[UIButton alloc] init];
	NSString *facultyAppPath = [[NSBundle mainBundle] pathForResource:@"Faculty_icon" ofType:@"png"];
	UIImage *facultyAppImage = [UIImage imageWithContentsOfFile:facultyAppPath];
	facultyAppButton.frame = CGRectMake(220, 240, 80, 80);
	[facultyAppButton setImage:facultyAppImage forState:UIControlStateNormal];
	[scrollView addSubview:facultyAppButton];
	[facultyAppButton addTarget:self action:@selector(OpenFacultyApp:) forControlEvents:UIControlEventTouchUpInside];
	[facultyAppImage release];
	[facultyAppPath release];
	
	UILabel *facultyAppLabel = UILabel.new;
	facultyAppLabel.frame = CGRectMake(220, 325, 80, 20);
	[scrollView addSubview:facultyAppLabel];
	facultyAppLabel.text = @"Faculty";
	facultyAppLabel.textAlignment = UITextAlignmentCenter;
	facultyAppLabel.backgroundColor = [UIColor clearColor];
	
	UIButton *studentActivitiesAppButton = [[UIButton alloc] init];
	NSString *studentActivitiesAppPath = [[NSBundle mainBundle] pathForResource:@"StudentActivities-icon" ofType:@"png"];
	UIImage *studentActivitiesAppImage = [UIImage imageWithContentsOfFile:studentActivitiesAppPath];
	studentActivitiesAppButton.frame = CGRectMake(340, 20, 80, 80);
	[studentActivitiesAppButton setImage:studentActivitiesAppImage forState:UIControlStateNormal];
	[scrollView addSubview:studentActivitiesAppButton];
	[studentActivitiesAppButton addTarget:self action:@selector(OpenStudentActivitiesApp:) forControlEvents:UIControlEventTouchUpInside];
	[studentActivitiesAppImage release];
	[studentActivitiesAppPath release];
	
	UILabel *studentActivitiesAppLabel = UILabel.new;
	studentActivitiesAppLabel.frame = CGRectMake(340, 105, 80, 20);
	[scrollView addSubview:studentActivitiesAppLabel];
	studentActivitiesAppLabel.text = @"Activities";
	studentActivitiesAppLabel.textAlignment = UITextAlignmentCenter;
	studentActivitiesAppLabel.backgroundColor = [UIColor clearColor];
}

- (IBAction)OpenMapApp:(id)sender {
	[[self navigationController] pushViewController:mapAppViewController animated:YES];
}

- (IBAction)OpenWavenetApp:(id)sender {
	[[self navigationController] pushViewController:wavenetAppViewController animated:YES];
}

- (IBAction)OpenCafeApp:(id)sender {
	[[self navigationController] pushViewController:cafeAppViewController animated:YES];
}

- (IBAction)OpenLibraryApp:(id)sender {
	[[self navigationController] pushViewController:libraryAppViewController animated:YES];
}

- (IBAction)OpenDivisionApp:(id)sender {
	[[self navigationController] pushViewController:divisionAppViewController animated:YES];
}

- (IBAction)OpenTempApp:(id)sender {
	[[self navigationController] pushViewController:tempAppViewController animated:YES];
}

- (IBAction)OpenAthleticsApp:(id)sender {
	[[self navigationController] pushViewController:athleticsAppViewController animated:YES];
}

- (IBAction)OpenConvocationApp:(id)sender {
	[[self navigationController] pushViewController:convocationAppViewController animated:YES];
}

- (IBAction)OpenCalendarApp:(id)sender {
	[[self navigationController] pushViewController:calendarAppViewController animated:YES];
}

- (IBAction)OpenFacultyApp:(id)sender {
	[[self navigationController] pushViewController:facultyAppViewController animated:YES];
}

- (IBAction)OpenStudentActivitiesApp:(id)sender{
	[[self navigationController] pushViewController:studentActivitiesAppViewController animated:YES];
}


- (void) pageTurn: (UIPageControl *) aPageControl {
	int whichPage = aPageControl.currentPage;
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:0.3f];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	scrollView.contentOffset = CGPointMake(320.0f * whichPage, 0.0f);
	[UIView commitAnimations];
}

- (void) scrollViewDidScroll: (UIScrollView *) aScrollView {
	CGPoint offset = aScrollView.contentOffset;
	pageControl.currentPage = (offset.x + 160) / 320.0f;
}

- (void)dealloc {
    [super dealloc];
}


@end
